import {
  Body,
  Controller,
  Get,
  Param,
  Patch,
  Query,
  UseGuards,
  ParseUUIDPipe,
} from '@nestjs/common';
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import {
  UserAdminIndexDto,
  UserAdminUpdateDto,
} from './user.dto';
import { UserService } from './user.service';
import {
  UserAdminIndexResult,
} from "@/module/user/user.result";
import { AdminAuthGuard } from "@/common/auth/admin-auth.guard";
import { getPager } from "@/common/pager-response";
import { PageResult } from "common/interface";
import { ApiPaginatedOkResponse } from "@/common/pager-response/api-paginated-ok-response.decorator";

@Controller('/v1/admin/users')
@ApiTags('User_admin')
@UseGuards(AdminAuthGuard)
export class UserV1AdminController {
  constructor(private readonly userService: UserService) {
  }

  @Get('/')
  @ApiOperation({ summary: '列表查询' })
  @ApiPaginatedOkResponse(UserAdminIndexResult)
  async index(@Query() query: UserAdminIndexDto): Promise<PageResult<UserAdminIndexResult>> {
    const res = await this.userService.adminIndex(query);
    return getPager(res[0], res[1]);
  }

  @Patch('/:uuid')
  @ApiOperation({ summary: '修改' })
  async update(
    @Body() body: UserAdminUpdateDto,
    @Param('uuid', ParseUUIDPipe) uuid: string,
  ): Promise<void> {
    await this.userService.adminUpdate(body, uuid);
    return;
  }
}
